﻿using System;
using Windows.ApplicationModel.Search;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using XnReader.WinRT.Forms;

// “用户控件”项模板在 http://go.microsoft.com/fwlink/?LinkId=234236 上提供

namespace XnReader.WinRT.Controlx
{
    /// <summary>
    /// 公共命令按钮
    /// </summary>
    public sealed partial class CommandDx : UserControl
    {
        public delegate void CommandDxEventHandler(object sender, RoutedEventArgs e);

        /// <summary>
        /// 目录/书签按钮点击事件
        /// </summary>
        public event CommandDxEventHandler ListClickEvent;

        /// <summary>
        /// 删除按钮点击事件
        /// </summary>
        public event CommandDxEventHandler DeleteClickEvent;

        /// <summary>
        /// 清空按钮点击事件
        /// </summary>
        public event CommandDxEventHandler CleanClickEvent;

        /// <summary>
        /// 修改按钮点击事件
        /// </summary>
        public event CommandDxEventHandler ModifyClickEvent;

        /// <summary>
        /// 导入本地按钮点击事件
        /// </summary>
        public event CommandDxEventHandler ImportClickEvent;

        /// <summary>
        /// 加入/取消书签
        /// </summary>
        public event CommandDxEventHandler MarkClickEvent;

        /// <summary>
        /// 背景选择
        /// </summary>
        public event CommandDxEventHandler BackgroundClickEvent;

        /// <summary>
        /// 字体大小
        /// </summary>
        public event CommandDxEventHandler FontSizeClickEvent;

        /// <summary>
        /// 返回
        /// </summary>
        public event CommandDxEventHandler GoBackClickEvent;

        /// <summary>
        /// 字体
        /// </summary>
        public event CommandDxEventHandler FontFamilyClickEvent;

        /// <summary>
        /// 编码
        /// </summary>
        public event CommandDxEventHandler EncodingClickEvent;

        /// <summary>
        /// 下一章
        /// </summary>
        public event CommandDxEventHandler NextClickEvent;

        /// <summary>
        /// 上一章
        /// </summary>
        public event CommandDxEventHandler PreviousClickEvent;

        /// <summary>
        ///
        /// </summary>
        public event CommandDxEventHandler SettingClickEvent;

        /// <summary>
        ///加入书架
        /// </summary>
        public event CommandDxEventHandler AddBookcaseClickEvent;

        
        /// <summary>
        /// 
        /// </summary>
        public CommandDx()
        {
            InitializeComponent();
        }

        private async void BtnClick(object sender, RoutedEventArgs e)
        {
            var button = sender as Button;
            if (button == null) return;
            switch (button.Name)
            {
                case "btnList":
                    {
                        if (ListClickEvent != null)
                            ListClickEvent(this, e);
                    }
                    break;
                case "btnOnlineStore":
                    {
                        //导航到在线首页
                        var rootFrame = Window.Current.Content as Frame;
                        if (rootFrame != null) rootFrame.Navigate(typeof(OnlineArticleList),string.Empty);
                    }
                    break;
                case "btnImport": //导入
                    {
                        if (ImportClickEvent != null)
                            ImportClickEvent(this, e);
                    }
                    break;
                case "btnDelete":
                    {
                        if (DeleteClickEvent != null)
                            DeleteClickEvent(this, e);
                    }
                    break;
                case "btnClean":
                    {
                        if (CleanClickEvent != null)
                            CleanClickEvent(this, e);
                    }
                    break;
                case "btnAbout":
                    {
                        //导航到关于页面
                        var rootFrame = Window.Current.Content as Frame;
                        if (rootFrame != null) rootFrame.Navigate(typeof(About));
                    }
                    break;
                case "btnMark":
                    {
                        if (MarkClickEvent != null)
                            MarkClickEvent(this, e);
                    }
                    break;
                case "btnBackground":
                    {
                        if (BackgroundClickEvent != null)
                            BackgroundClickEvent(this, e);
                    }
                    break;
                case "btnFontSize":
                    {
                        if (FontSizeClickEvent != null)
                            FontSizeClickEvent(this, e);
                    }
                    break;
                case "btnFontFamily":
                    {
                        if (FontFamilyClickEvent != null)
                            FontFamilyClickEvent(this, e);
                    }
                    break;
                case "btnModify":
                    {
                        if (ModifyClickEvent != null)
                            ModifyClickEvent(this, e);
                    }
                    break;
                case "btnGoBack":
                    {
                        if (GoBackClickEvent!= null)
                            GoBackClickEvent(this, e);
                    }
                    break;
                case "btnEncoding":
                    {
                        if (EncodingClickEvent != null)
                            EncodingClickEvent(this, e);
                    }
                    break;
                case "btnRating":
                    {
                        await Windows.System.Launcher.LaunchUriAsync(new Uri(@"ms-windows-store:REVIEW?PFN=55701Z4.506D7CDA589_fc3gqrpkhdn6p"));
                    }
                    break;
                case "btnUpdate":
                    {
                        await Windows.System.Launcher.LaunchUriAsync(new Uri(@"ms-windows-store:Updates"));
                    }
                    break;
                case "btnNext":
                    {
                        if (NextClickEvent != null)
                            NextClickEvent(this, e);
                    }
                    break;
                case "btnPrevious":
                    {
                        if (PreviousClickEvent != null)
                            PreviousClickEvent(this, e);
                    }
                    break;
                case "btnBookcase":
                    {
                        //导航到书架
                        var rootFrame = Window.Current.Content as Frame;
                        if (rootFrame != null) rootFrame.Navigate(typeof(BookcaseDx));
                    }
                    break;
                case "btnSearch":
                    {
                        SearchPane.GetForCurrentView().Show();
                    }
                    break;
                case "btnSetting":
                    {
                        if (SettingClickEvent != null)
                            SettingClickEvent(this, e);
                    }
                    break;
                case "btnAddBookcase":
                    {
                        if (AddBookcaseClickEvent != null)
                            AddBookcaseClickEvent(this, e);
                    }
                    break;
            }
        }
    }

    public class CommandInfo
    {
        private string _theme = "black";

        /// <summary>
        /// 工具栏的主题色
        /// </summary>
        public string Theme
        {
            get { return _theme; }
            set { _theme = value; }
        }

        private Visibility _visibleList = Visibility.Collapsed;

        public Visibility VisibleList
        {
            get { return _visibleList; }
            set { _visibleList = value; }
        }

        private Visibility _visibleDelete = Visibility.Collapsed;

        public Visibility VisibleDelete
        {
            get { return _visibleDelete; }
            set { _visibleDelete = value; }
        }

        private Visibility _visibleClean = Visibility.Collapsed;

        public Visibility VisibleClean
        {
            get { return _visibleClean; }
            set { _visibleClean = value; }
        }

        private Visibility _visibleModify = Visibility.Collapsed;

        public Visibility VisibleModify
        {
            get { return _visibleModify; }
            set { _visibleModify = value; }
        }

        private Visibility _visibleAbout = Visibility.Collapsed;

        public Visibility VisibleAbout
        {
            get { return _visibleAbout; }
            set { _visibleAbout = value; }
        }

        private Visibility _visibleLogo = Visibility.Collapsed;

        public Visibility VisibleLogo
        {
            get { return _visibleLogo; }
            set { _visibleLogo = value; }
        }

        private Visibility _visibleOnlineStore = Visibility.Collapsed;

        public Visibility VisibleOnlineStore
        {
            get { return _visibleOnlineStore; }
            set { _visibleOnlineStore = value; }
        }

        private Visibility _visibleImport = Visibility.Collapsed;

        public Visibility VisibleImport
        {
            get { return _visibleImport; }
            set { _visibleImport = value; }
        }

        private Visibility _visibleGoBack = Visibility.Collapsed;

        public Visibility VisibleGoBack
        {
            get { return _visibleGoBack; }
            set { _visibleGoBack = value; }
        }

        private Visibility _visibleMark = Visibility.Collapsed;

        public Visibility VisibleMark
        {
            get { return _visibleMark; }
            set { _visibleMark = value; }
        }

        private Visibility _visibleBackground = Visibility.Collapsed;

        public Visibility VisibleBackground
        {
            get { return _visibleBackground; }
            set { _visibleBackground = value; }
        }

        private Visibility _visibleFontSize = Visibility.Collapsed;

        public Visibility VisibleFontSize
        {
            get { return _visibleFontSize; }
            set { _visibleFontSize = value; }
        }

        private Visibility _visibleFontFamily = Visibility.Collapsed;

        public Visibility VisibleFontFamily
        {
            get { return _visibleFontFamily; }
            set { _visibleFontFamily = value; }
        }

        private Visibility _visibleRating = Visibility.Collapsed;

        public Visibility VisibleRating
        {
            get { return _visibleRating; }
            set { _visibleRating = value; }
        }

        private Visibility _visibleUpdate = Visibility.Collapsed;

        public Visibility VisibleUpdate
        {
            get { return _visibleUpdate; }
            set { _visibleUpdate = value; }
        }

        private Visibility _visibleNext = Visibility.Collapsed;

        public Visibility VisibleNext
        {
            get { return _visibleNext; }
            set { _visibleNext = value; }
        }

        private Visibility _visiblePrevious = Visibility.Collapsed;
        public Visibility VisiblePrevious
        {
            get { return _visiblePrevious; }
            set { _visiblePrevious = value; }
        }

        private Visibility _visibleBookcase = Visibility.Collapsed;
        public Visibility VisibleBookcase
        {
            get { return _visibleBookcase; }
            set { _visibleBookcase = value; }
        }

        private Visibility _visibleSearch = Visibility.Collapsed;
        public Visibility VisibleSearch
        {
            get { return _visibleSearch; }
            set { _visibleSearch = value; }
        }

        private Visibility _visibleSetting = Visibility.Collapsed;
        public Visibility VisibleSetting
        {
            get { return _visibleSetting; }
            set { _visibleSetting = value; }
        }

        private Visibility _visibleAddBookcase = Visibility.Collapsed;
        public Visibility VisibleAddBookcase
        {
            get { return _visibleAddBookcase; }
            set { _visibleAddBookcase = value; }
        }
    }
}
